home *** CD-ROM | disk | FTP | other *** search
Wrap
Text File | 1992-04-17 | 9.6 KB | 204 lines | [ TEXT/PJMM]
unit Grafsys; interface (* uses *) (* Matrix, Transformations, Data3D, ResourceAccess; *) const Res3D = '3Dob'; (* This is the 3D object data resource name *) MXP = 100; (* maximum number of Points in Object*) MXL = 200; (* maximim number of lines in Object *) MXPoly = 30; (* maximum number of Polygons per Object *) MaxPolyLine = 10; (* Maximum Number of Lines per Polygon *) Pi = 3.14159265; (* projection Types *) parallel = 0; perspective = 1; (* Erase Types *) ObjRectFill = 0; XorLines = 1; WhiteLines = 2; (* draw all Lines in White *) BlackLines = 3; (* draw all Lines in Black *) type ptsArray = array[1..MaxPolyLine] of integer; Polygon = record deepz: real; (* maximum (=deepest) z coordinate of this Polygon. For use with HiddenLine/surface *) PointsInPoly: integer; (* number of Lines in this Polygon *) points: ptsArray; (* reference to the Points that make out the Polygon *) Flag: Boolean; (* General Purpose Flag, used in DepthSort *) end; Matrix4 = array[1..4, 1..4] of real; Vector4 = array[1..4] of real; Point3D = Vector4; Line3D = record startpoint, endpoint: Integer; (* Number of 3D-point to draw from and to, both must be within 1 and obj.maxpoint *) newline: boolean; (* Indicates that startpoint is not endpoint from last Line3D *) end; PointArray = array[1..MXP] of Point3D; LineArray = array[1..MXL] of Line3D; PolyArray = array[1..MXPoly] of Polygon; Eye3D = record location: Point3D; phi: Real; theta: Real; pitch: Real; ViewAngle: Real; end; Graf3DPtr = ^Grafport3D; Grafport3D = record ProjectionPlane: Rect; ViewPlane: Rect; left, right, top, bottom: Integer; (* Window rectangle *) center: Point; (* center of screen *) MasterTransform: Matrix4; (* Matrix for pretrafo for eye-coords *) eye: Eye3D; (* the Eye of the Camera *) UseEyeFlag: Boolean; (* FALSE --> eye is always at (0,0,0) and looks straight down z *) d: Real; (* Perspective Parameter set up by Viewangle *) Clip: Boolean; (* Tells algorithm if to clip to 3D Pyramid *) HiddenLine: Boolean; (* use Hidden-Line Algorithm on Object *) projectionType: INTEGER; (* parallel or perspective *) versionID: LongInt; (* used to identify changes *) end; screenArray = array[1..MXL] of integer; (* note : mxL, for all screencoords will be stored for all lines *) screenPts = array[1..MXP] of integer; newLineArray = array[1..MXl] of Boolean; (* ScreenObj : This Data Structure holds an Transformed Object and all its data required to draw it on screen *) (* OOP : should be an instant of Object3D *) ScreenObjPtr = ^ScreenObj; ScreenObj = record nhmin, nhmax, nvmin, nvmax: integer; (* new rectangles from last calculation *) hmin, hmax, vmin, vmax: integer; (* Rectange in which ScreenObject from SECOND LAST call to ClacScreenObj *) Point: PointArray; (* Transformed Points of object *) deepz: real; (* maximum z of all Transformed Points. Used for Scene-Building *) maxPoint, maxLine, maxPoly: integer; (* number of Points, Lines and Polygons in this Object *) Line: LineArray; (* Lines as defined in Parent Object *) screenx: screenPts; (* x-coordinates of all Transformed Points *) screeny: screenPts; (* y-coordinates of all Transformed Points *) screenLines: integer; Autoerase: Boolean; EraseType: Integer; (* The following data should be used as instances of the same basic object if we convert to *) (* OOP Grafsys. *) screen1x: ScreenArray; (* x-coordinates for clipped lines in CxxxScreenObj *) screen1y: ScreenArray; (* - " - *) screen2x: screenArray; (* used in Line-Clipping mode *) screen2y: screenArray; (* - " - *) newLine: newLineArray; (* - " - *) Polygons: PolyArray; (* Polygons as defined in Parent Object *) (* debugging only variables follow *) end; (* GrafObj : The Representation of Objects for Object Drawing and Transformation *) (* OOP : would be Object3D *) GrafObjPtr = ^GrafObject; GrafObject = record versionID: LongInt; (* used to identify changes in Eye*) hasChanged: Boolean; (* will be set TRUE after any change to Object *) x, y, z: Real; (* position of object's Origin in 3D-space *) xRot, yRot, zRot: Real; (* rotation of Object to its own origin *) sx, sy, sz: Real; (* objects scaling factors *) Trot: Matrix4; (* internal use : objects trafo-matrix for rotation*) Ttrans: Matrix4; (* internal use only : objects trafo Matrix for translation and scaling *) Tanyrot: Matrix4; (* matrix for additional rotation around any achsis *) Tfreeform: Matrix4; (* internal use only : free translation of object *) maxPoint: Integer; (* number of points in Object, max 100, min 2 *) maxLine: Integer; (* number of Lines in Object, max 200, min 1 *) maxPoly: Integer; (* number of Polygons in Object *) Point: PointArray; Line: LineArray; Polygons: PolyArray; vmax: integer; (* this objects maximal and minimal screen coords after last draw *) vmin: integer; hmin: integer; hmax: integer; AutoErase: Boolean; (* Flag for use with vmax..hmax and the fDrawObject routine *) hasDrawn: Boolean; (* internal use only : for use with erase flag *) EraseType: INTEGER;(* What kind of Erase-Technique for Autoerase *) ScreenObjLink: ScreenObjPtr; (* attached screenobject. defaults to NIL *) end; (* procedures to manipulate Grafport *) procedure InitGrafSys; (* (var Master: Graf3DPtr) -- deleted, since we have GetGrafPort *) procedure NewGrafport (thePlane: Rect; var the3DPort: Graf3DPtr); procedure SetGrafPort (the3DPort: Graf3Dptr); (* tells grafsys in which port to draw *) procedure GetGrafPort (var the3DPort: Graf3dptr); (* get current GrafPort *) procedure SetView (ProjectPlaneSize, ViewPlaneSize: Rect); procedure SetCenter (x, y: INTEGER); procedure SetEye (UseEye: Boolean; x, y, z: REAL; phi, theta, pitch: real; viewangle: real; clipping: boolean); procedure geteye (var UseEye: Boolean; var x, y, z, phi, theta, pitch, viewangle: real; var clipping: boolean); (* routines to generate objects *) function NewObject: GrafObjPtr; function GetNewObject (theObjectID: INTEGER): GrafObjPtr; function GetNewNamedObject (theObjectName: Str255): GrafObjPtr; procedure SaveObject (theObject: GrafObjPtr; theName: Str255; ID: integer); procedure SaveNamedObject (theObject: GrafObjPtr; theName: Str255; var ID: integer); function AddPoint (theObject: GrafObjPtr; x, y, z: Real; var PointCount: integer): boolean; function DeletePoint (theObject: GrafObjPtr; PointNumber: integer): Boolean; procedure GetPoint (theObject: GrafObjPtr; thePoint: INTEGER; var x, y, z: REAL); procedure ChangePoint (theObject: GrafObjPtr; thePoint: integer; x, y, z: real); function AddLine (theObject: GrafObjPtr; src, tgt: integer): Boolean; function DeleteLine (theObject: GrafObjPtr; theLine: INTEGER): Boolean; function ChangeLine (theObject: grafObjPtr; theLine: INTEGER; src, tgt: INTEGER): Boolean; procedure GetLine (theObject: GrafObjPtr; theLine: INTEGER; var src, tgt: INTEGER; var newline: boolean); function SetPoly (p1, p2, p3, p4, p5, p6, p7, p8, p9, p10: integer): polygon; procedure AddPolygon (theObject: GrafObjPtr; thePolygon: Polygon; var PolyRef: Integer); (* does NOT polygon must have been created *) function AddPointToPolygon (theObject: GrafObjPtr; thePolyref, thePointRef: Integer): boolean; (* routines to manipulate object in 3D locally/operationorder-idependent*) procedure ResetObject (theObject: GrafObjPtr); (* sets objects rotation and position of origin to 0 *) procedure ObjRotate (theObject: GrafObjPtr; dXrot, dYrot, dZrot: real); procedure SetObjRot (theObject: GrafObjPtr; Xrot, Yrot, Zrot: real); procedure GetObjRot (theObject: GrafObjPtr; var Xrot, Yrot, Zrot: real); procedure ObjTranslate (theObject: GrafObjPtr; dx, dy, dz: Real); procedure SetObjTranslate (theObject: GrafObjPtr; xTrans, yTrans, zTrans: Real); procedure GetObjTranslate (theObject: grafObjPtr; var xTrans, yTrans, zTrans: Real); procedure ObjScale (theObject: GrafObjPtr; sx, sy, sz: Real); procedure SetObjScale (theObject: GrafObjPtr; xScale, yScale, zScale: Real); procedure GetObjScale (theObject: grafObjPtr; var xScale, yScale, zScale: Real); procedure ObjRotateArb (theObject: GrafObjPtr; p1, p2: Vector4; phi: Real); (* rotate local around arbitrary achsis *) procedure ResetAnyRot (theObject: GrafObjPtr); function ObjPoint (theObject: GrafObjPtr; thePoint: Integer): Vector4; (* returns the coordinates of object's point if rotation where done *) function ObjPointArb (theObject: GrafObjPtr; x, y, z: Real): Vector4; (* routines to manipulate object in 3D globally/operation-dependent *) procedure ObjFreeRotate (theObject: GrafObjPtr; dXrot, dYrot, dZrot: real); procedure ObjFreeRotateArb (theObject: GrafObjPtr; p1, p2: Vector4; phi: Real); procedure ObjFreeTranslate (theObject: GrafObjPtr; dx, dy, dz: Real); procedure ObjFreeReset (theObject: GrafObjPtr); (* routines to prepare to draw in 3D *) procedure SetAutoErase (theObject: GrafObjPtr; Flag: Boolean); procedure setprojection (theGrafPort: Graf3DPtr; projectionType: INTEGER); procedure ToScreen (x, y, z: real; var h, v: INTEGER); procedure TransformObject (theObject: GrafObjPtr; var xPointBuf, ypointBuf: screenPts; var hmin, vmin, hmax, vmax: integer; var deepz: Real; var Points: PointArray); implementation end.